﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


using nplJobsCommon.Common;


namespace nplJobsDAL.Select
{
    /// <summary>
    /// Select industries from the database
    /// </summary>
    public class SelectIndustry : DataAccessBase
    {
         public SelectIndustry()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectIndustry.ToString();
        }

         #region GetIndustry
         public List<Industry> GetIndustry()
        {
            DataBaseHelper dbHelper;
            DataSet dsIndustry;

            try
            {
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dsIndustry = dbHelper.Run(base.ConnectionString);
                return GetList(dsIndustry);
            }
            catch (Exception)
            {

                throw;
            }
        } 
        #endregion

         #region GetList
         private List<Industry> GetList(DataSet dsIndustry)
        {
            List<Industry> industries;
            try
            {
                industries = (from n in dsIndustry.Tables[0].AsEnumerable()
                                 select new Industry
                                 {
                                     ID = n.Field<int>("ID"),
                                     Name = n.Field<string>("Name")
                                 }).ToList();

                return industries;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        } 
        #endregion
    }
}
